﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace MotionControl.Modules.LightSource.Models
{
    public class IntensityRule: ValidationRule
    {
        public int Min { get; set; } = 0;
        public int Max { get; set; } = 255;

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            var intensity = 0;
            try
            {
                if (((string)value).Length > 0)
                    intensity = int.Parse((string)value);
            }
            catch (Exception e)
            {
                return new ValidationResult(false, "Illegal characters or " + e.Message);
            }

            if ((intensity < Min) || (intensity > Max))
            {
                return new ValidationResult(false,
                    "Please enter an age in the range: " + Min + " - " + Max + ".");
            }
            return new ValidationResult(true, null);
        }
    }
}
